package org.hackystat.ambientdevice.trigger;

import java.io.Serializable;
import java.util.Comparator;
import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorDataRef;

/**
 * Class that compares SensorData by its date.
 * 
 * @author Shaoxuan Zhang
 */
public class CompareSensorDataRefByDate implements Comparator<SensorDataRef>, Serializable {

  /**
   * serialVersionUID.
   */
  private static final long serialVersionUID = 3763521540646279352L;

  /**
   * method that implement the comparation.
   * 
   * @param data1 the first SensorData
   * @param data2 the second SensorData
   * @return The relationship between these two SensorData. -1 if LESSER, 0 if EQUAL, 1 if GREATER
   */
  public int compare(SensorDataRef data1, SensorDataRef data2) {
    int result = data1.getTimestamp().compare(data2.getTimestamp());
    if (result == 2) {
      result = 0;
    }
    return result;
  }

}
